import random

from faker import Faker

fake = Faker(locale='zh-CN')


def yaml_func(data):
    if isinstance(data, dict):
        for key, value in data.items():
            if '${' and '}' in str(value):
                start = str(value).index('${')
                end = str(value).index('}')
                func_name = str(value)[start + 2:end]
                data[key] = eval(func_name)
    return data


def random_name():
    return fake.name()


def age():
    return random.randint(10, 90)


if __name__ == '__main__':
    data = {'name': '${random_name()}', 'age': '${age()}', 'sex': '男'}
    print(yaml_func(data))
